#include <kernel/types.h>
#include <kernel/stat.h>
#include <user/user.h>

int main()
{
    int pid,pid1;
    int pipe1[2],pipe2[2];
    char temp[6] = {};
    pipe(pipe1);
    pipe(pipe2);

    pid = fork();
    if(pid < 0) exit(-1);

    if(pid == 0)    //children process
    {
        pid1 = getpid();
        close(pipe1[1]);
        close(pipe2[0]);
        read(pipe1[0],temp,4);
        printf("%d recieve %s\n",pid1,temp);
        write(pipe2[1],"pong",4);
        exit(0);
    }
    else
    {
        pid1 = getpid();
        close(pipe1[0]);
        close(pipe2[1]);
        write(pipe1[1],"ping",4);
        read(pipe2[0],temp,4);
        printf("%d receive %s\n",pid1,temp);
        exit(0);
    }
}
